package com.imti.mall.common.exception;

import com.imti.mall.common.Api.IErrorCode;
import lombok.Data;

/**
 * 自定义业务异常，用于处理用户请求时，业务错误时抛出
 */

@Data
public class BusinessException extends RuntimeException {

    private IErrorCode errorCode;

    public BusinessException(IErrorCode resStatus) {
        //不调用父类Throwable的fillInStackTrace()方法生成栈追踪信息，提高应用性能
        //构造器之间的调用必须在第一行
        super(resStatus.getMessage(), null, false, false);
        this.errorCode = resStatus;
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public IErrorCode getErrorCode() {
        return errorCode;
    }

}
